home *** CD-ROM | disk | FTP | other *** search
- KNOW-HOW 4.x
- GUI LIBRARY WITH EXTENTIONS
- SOURCE CODES
- BORLAND C++ 3.X, DOS
- (C) Stepan S. Vartanov, 1992, 93, 94
-
- INTRODUCTION.
- KNOW-HOW is a library for BC 3.x. It includes:
- KNOW-HOW.Interface with windows, icons, menus, PCX support,
- screen output of LJ (SFP) fonts and so on. EGA/VGA 16 colors. KHI
- also provides support scripts: user could record keyboard pressings
- to file, play them or link them with any "hot key". Window system
- supports multiple overlapped windows, and could simulate switching
- between tasks.
- KNOW-HOW.BGI. Abstract drawing functions for vector primitives
- with zooming, rotation, mirror and scrolling, and concrete represen-
- tation - BGI child class.
- KNOW-HOW.DRAW. PaintBrush-like PCX-editor (source codes),
- designed as part of KH hierarchy. Could be included to user's program
- without changing any code at all.
- KNOW-HOW.PRINT. Keep on disk RGB screen of any size, scroll it
- in clip region on screen, with or without deformation, print this
- screen or part of it on printers of different types with or without
- deformation.
- KNOW-HOW.GRAF. Plot on screen graphics using "LINES and
- MARKERS", "BAR", "3D BAR" or "STACKED BAR" presentation. Manual or
- automatic mark axes.
- KNOW-HOW.SLANG. Basic - like language. It's child (C++
- terminology) could have functions to axess facilities of concrete
- package. Usage: any spreadsheets, calculators, and creating languages
- for integrated packages.
- KNOW-HOW.SLANG.DRAW. SLANG-based drawind tool, vector graphics
- editor. The new language derived from SLANG have additional functions
- for graphic output. KNW-HOW could be connected with this tool to
- produce interactive painting program.
- KNOW-HOW.DATASHELL. Extention for BORLAND PARADOX ENGINE 3.01.
- View, edit or ask tables, Multytable QBE and so on.
- KNOW-HOW.DEBUG. Creates protocol of memory operations (new and
- delete) of program, even if it handles computer. Very powerful tool.
-
- HOW TO STUDY KNOW-HOW.
-
- Library complectation includes all source codes. They are
- commented enought to giude themself. In addition almost every CPP
- file contains remarked main() function which illustrate usage of the
- concrete class. Example projects are ready to compile. They are
- designed to explain the KNOW-HOW ideas, and could be used as real
- commercial programs prototypes. Few aspects which require the special
- discussion are documented here.
-
- Class Visible.
- All classes of KNOW-HOW which are able to interact with user are
- derived from this class. The base class in KH hierarchy. Please read
- attentively all the comments to file.
-
- FILE VISIBLE.H
- /* Base class for any classes which may be put to interface container
- (ObjectKit, ApplicationKit ...).
- "ret" is the flag, it determines the behaviour of object after
- it lost the control (See below).
- exe() is the main function of object, it executes every time
- when we choice object. WINDOWS synonym is WndProc() function.
-
- "event" structure contains information about type of event
- happened, coordinates of mouse cursor and so on. Menu and some other
- objects may replace events, for example, mouse pressing on "exit"
- button may be replaced with keyboard "EVENT_ESC".
- "action_type" contains type of action (user-defined function) of
- the last used object, or 0.
- "global_num" contains number of menu item, global_i[0] contains
- action_type value. To read more about reserved variables of KNOW-HOW,
- see file GLOBAL.H.
- */
-
- #ifndef __VISIBLE_H_
- #define __VISIBLE_H_
-
- #include "addevent.h" // Event handler, the most complete version.
- #include "action.h" // Reserved messages of KNOW-HOW
- #include "global.h" // Temporary storage structures.
-
- enum where_mouse { MOUSE_OUT, MOUSE_IN };
-
- enum ret_flags { RET_OK = 1, RET_CANCEL = 2, RET_MOUSE = 4,
- RET_ANY = 7, RET_TRANSFER = 8, RET_REMOVE = 16,
- RET_SHOW = 32, RET_STACKED = 64 };
- /* RET_ message transfer. This flags control is it necessary to
- remove object from screen when input focus is lost. RET_ANY is their
- combination.
- For example, we work with file list, and click 22-thmenu item.
- If bit RET_TRANSFER == 0, control will be passed to object pointTo +
- 22 - 1 (PointTo is the number of next object, and callForm - number
- of previous). If RET_TRANSFER == 1, object pass control to object
- with number (in upper container) pointTo.
- */
-
- class Visible
- {
- protected:
- int object_number; // Number of base window.
- int ret; // Group of flags.
- int pointTo; // Object to pass control if OK EVENT handled.
- int callFrom; // Object to pass control if CANCEL EVENT.
- int action_type; // What to do after OK EVENT.
- int once; // Is the object active?
-
- public:
- Visible()
- { once = ret = pointTo = callFrom = action_type =
- object_number = 0; }
-
- virtual ~Visible() { }
- int active() { return once; } // Is it active
- void set_active(int a) { once = a; }
- int get_object_number() { return object_number; }
- void set_object_number(int n) { object_number = n; }
- virtual void repose(rect ) {}
- /* For every object we could write the analog of constructor. We call
- it after resizing of base window in container. This function will
- recalculate coordinates of all elements of class.
- */
- int isRet(int what) { return ret & what; }
- // For example: isRet(RET_OK | RET_CANCEL)
- int isPoint() { return pointTo; }
- int isAct() { return action_type; } // ACTION.H and user's
- int isCall() { return callFrom; }
-
- void assign(int pnt, int act_type)
- // Links objects. Assign action to object.
- {
- pointTo = pnt;
- action_type = act_type;
- }
-
- void set_call(int call) { callFrom = call; }
- void set_point(int p) { pointTo = p; }
-
- void set_ret(int r) { ret = r; }
- // F.e.: set_ret(RET_OK | RET_CANCEL)
-
- virtual void exe(int act = 0) = 0;
- // Main function - user interface.
- virtual void show() = 0; // Show the object
- virtual void hide() {}
- where_mouse mouse_in(loc l)
- // Is the mouse inside this object or outside. contains() and
- // other KNOW-HOW geometry see GEOM.H and GRAPHPP.H
- { return (where_mouse)(bound().contains(l)); }
- virtual rect bound() = 0; // Rectangle including this object
- virtual void touch(int i = 0) {}
- // Fill global_... structures reserved by KNOW-HOW with
- // class-specific data
- };
-
- #endif __VISIBLE_H_
-
-
- SIMPLIFIED CLASS INTERFACE.
-
- Here is the brief discussion of how KNOW-HOW operates with
- windows and menus.
- Usually, object-oriented event driven systems used complicated
- event handlers. Single action, as "Close The Window" generate cascade
- of child messages. The main task of SCI is to use single message with
- the same effect. Object's reaction to some events is determined, and
- SCI guaranties that class will never meet with another events and
- messages (so called "soldier - serguant principle").
-
- FLOW CONTROL IN KNOW-HOW.
-
- Lets discuss event processing (event handling - see next
- chapter). We shell call "container" the class, which keep list of
- pointers to other objects, including containers. KNOW-HOW use 3
- levels of containers:
- OBJECT (menu with mouse buttons)
- APPLICATION (example - Borland IDE)
- PROGRAM (example two Paintbrushes, running under Windows).
- SCI provide 3 ways to leave object: with OK message (RETURN
- pressed on menu item), with CANCEL message (ESC pressed), or when
- mouse button is pressed outside of object. To determine object's
- behaviour SCI use 3 bits of variable "ret":
- enum { RET_OK = 1, RET_CANCEL = 2, RET_MOUSE = 4 ...
- This flags control is it necessary to remove object from screen
- when input focus is lost. RET_ANY is their combination.
- Lets, for example, working with file list we click 22-thmenu
- item. If bit RET_TRANSFER == 0, control will be passed to object
- pointTo + 22 - 1 (PointTo is the number of next object, and callForm
- - number of previous). If RET_TRANSFER == 1, object pass control to
- object with number (in upper container) pointTo.
- Another example. We are working with menu NEW, OPEN, SAVE. Last
- two items should call object "file menu". The following code shows
- the solution:
-
- Header:
- enum { AC_USER = 101, ... AC_NEW, AC_OPEN, AC_SAVE... };
- extern int file;
- enum { NEW, OPEN, SAVE };
-
- CPP file:
- int file = NEW;
- void application(int action_number)
- // User functions. Every program should contain it's version.
- {
- ...
- switch(action_number)
- {
- ...
- case AC_NEW: new_file(); return 1;
- /* new_file() is user-defined function, return value: 1 - pass
- control to prev. object in menu cascade, 0 - keep control, 2 - call
- next object.
- */
- case AC_OPEN: file = OPEN; return 2;
- case AC_SAVE: file = SAVE, return 2;
- ....
- case AC_FILE:
- switch(file)
- {
- case OPEN: open_file(); break;
- case SAVE: save_file(); break;
- }
- return 1;
- ....
- NEW choice will call new_file() function, and then remove menu
- from screen. OPEN or SAVE will pass control to file menu, and after
- its execution open_file() or save_file() is called.
- The next problem is: how do we know that next object is namely
- file menu? Filling the Application container we should use the
- following code:
-
- ApplicatioKit* kit = new... // Constructor
- kit->add(menu); // NEW, OPEN, SAVE menu
- ...
- kit->add(file_sys); // file menu
- ...
- menu->set_ret(...RET_TRANSFER...);
- assign(file_sys, menu, AC_NEW);
- assign(..., file_sys, AC_FILE);
-
- All items of menu points to the same object (RET_TRANSFER is 1),
- user function of 1-st position of the "menu" is AC_NEW (AC_NEW + 1
- for second position and so on), and user function of file_sys is
- AC_FILE.
-
- RET_REMOVE flag means that object will be removed from container
- when ALT/F3 pressed (usefull in multywindw systems).
- RET_SHOW forses the system to redraw all window every time it
- becomes active.
- RET_STACKED determines type of the window. If it is 0, that is
- popup window, and if it is 1, window could be invoked in the multiple
- overlapped windows system. Usually, popup windows are used in cascade
- menus or dialogs.
-
- USER-DEFINED FUNCTIONS.
-
- KNOW-HOW reserves functions (messages) with numbers 0 - 100.
- User could to register his own messages with numbers 101 - ... For
- example:
- #define AC_COLOR 101 // Registration
-
- application(int act)
- {
- switch(act)
- {
- ...
- case AC_COLOR: setcolor(RED); return 0;
- ...
-
- Object keep the number of its function in data element
- "action_type". If object may call different functions (menu),
- action_type is the FIRST function in list of possible choices.
- Reserved actions see the file ACTION.H
-
- Any event was happened (RETURN pressing, f.e.). Object which
- have had focus of input get this message and, depending of the value
- of its "ret" class data member hide (or not) itself. Then if it was
- "OK"-type event, application(action_type) is called. There are 3
- possible scenaries after execution of this function: go to previous
- object, keep control in current object or go to the next object.
- Numbers of objects (numbers of pointers to them in the list of upper-
- level container) are in callFrom and pointTo class variables. The
- concrete scenary depends of the number (0, 1, 2) returned by user-
- defined function.
-
- EVENTS.
-
- Event handler (ACTION.H, EVENT.H, MOUSE.H and so on, see
- EVENT.PRJ). Files are good documented, so only brief description is
- given.
- There are 4 types of events: NOEVENT, KEYEVENT, SHIFTKEYEVENT
- (CTRL, ALT, SHIFT and Lock... keys involved), MOUSEEVENT. Delpressed
- is not eq. to 0 if DEL key is holded.
- The most important mouse events: MOUSELEFT, MOUSERIGHT,
- MOUSECENTER, MOUSELEFT2 ...
- To get information use getevent(), readevent() and eventavail()
- functions. Parameters of this functions are OR-combination of
- constants mentioned above: KEYEVENT, SHIFTKEYEVENT and MOUSEEVENT.
-
- INTERFACE COLORS.
-
- File COLORS.SET contains few standart color sets in format:
- COLOR comment
- COLOR comment
- COLOR comment
- ....
- @ end of set No 1
- COLOR comment
- COLOR comment
- COLOR comment
- ...
-
- Colors could be changed using load_set_color(int COLORSETNUM)
- function.
- Objects of KNOW-HOW could also use different fill patterns (in
- PATTERNS.CPP):
- char pattern[][8] =
- { { 255, 255, 255, 255, 255, 255, 255, 255 },
- ...........................................
-
- GEOMETRY.
-
- GEOM.H file defines geom. objects in C++ manner: loc(x, y)
- defines pint, rect(x1, y1, x2, y2) - rectangle and so on.
- GRAPHPP.H file overload BGI functions using GEOM.H structures.
-
- SCRIPTS AND MACROSES.
-
- Event manager could use events, which was previuosly recorded to
- file. get_event() funtion (file ADEVENT) uses global flag
- SCRIPT_MODE. If it is equial to RECORD, all user input is duplicated
- to file scriptFileName (GLOBAL.H). If it is PLAY, event source is
- file, not keyboard. See examples of scripts and macroses
- (MACROS.MAC).
-
-